import java.util.Collections;
import java.util.List;

public class FindMinDifference {

    public int findMinDifference(List<String> timePoints) {
        if (timePoints.size() > 1440) return 0;
        Collections.sort(timePoints);
        int temp = process(timePoints.get(0));
        int ans = 24 * 60 - (process(timePoints.get(timePoints.size() - 1)) - temp);
        for (int i = 1; i < timePoints.size(); i++) {
            int m = process(timePoints.get(i));
            ans = Math.min(ans, m - temp);
            temp = m;
        }
        return ans;
    }

    public int process1(String a, String b) {
        int aH = Integer.parseInt(a.substring(0, 2));
        int bH = Integer.parseInt(b.substring(0, 2));
        int aM = Integer.parseInt(a.substring(3, 5));
        int bM = Integer.parseInt(b.substring(3, 5));
        int ans = (bH - aH) * 60 + (bM - aM);
        return Math.min(ans, 24 * 60 - ans);
    }

    public int process(String a) {
        return ((a.charAt(0) - '0') * 10 + a.charAt(1)) * 60 + (a.charAt(3) - '0') * 10 + a.charAt(4) - '0';
    }
}
